package cn.zl.web.dto.dashboard;

import cn.yunbamboos.rest.service.dto.Data;
import cn.yunbamboos.rest.service.dto.out.GenericOutDTO;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class DashboardStatisticsOutDTO extends GenericOutDTO {

    private final List<StatisticsItem> statisticsItemList = new ArrayList<>();

    public DashboardStatisticsOutDTO() {
    }

    public void addStatisticsItem(String title, boolean enable, int num, int total) {
        StatisticsItem item = new StatisticsItem();
        item.title = title;
        item.enable = enable;
        item.num = num;
        item.total = total;
        statisticsItemList.add(item);
    }

    @Override
    public void encode(Data data) {
        super.encode(data);
        JSONArray statisticsList = new JSONArray();
        for (StatisticsItem item : statisticsItemList) {
            JSONObject json = new JSONObject();
            json.put("title", item.title);
            json.put("enable", item.enable);
            json.put("num", item.num);
            json.put("total", item.total);
            statisticsList.add(json);
        }
        data.set("statistics_list", statisticsList);
    }

    public static class StatisticsItem {
        String title;
        boolean enable;
        int num;
        int total;
    }
}
